<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="125px">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系方式" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入联系方式" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="岗位类型" prop="position">
        <el-select v-model="queryParams.position" placeholder="请选择岗位类型" clearable>
          <el-option v-for="dict in dict.type.c_position" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="交付小组" prop="payGroupName">
        <el-input v-model="queryParams.payGroupName" placeholder="请输入交付小组名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="课程分类" prop="classTypeName">
        <el-input v-model="queryParams.classTypeName" placeholder="请输入课程分类" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所学教段" prop="teachSection">
        <el-input v-model="queryParams.teachSection" placeholder="请输入所学教段" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="CoachList">
      <el-table-column label="交付中心编号" align="center" prop="paCenterCode" />
      <el-table-column label="交付中心名称" align="center" prop="paCenterName" />
      <el-table-column label="教练姓名" align="center" prop="name" />
      <el-table-column label="账号" align="center" prop="phone" />
      <el-table-column label="课程分类" align="center" prop="classTypeName" />
      <el-table-column label="授课方式" align="center" prop="teachMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.c_teach_method" :value="scope.row.teachMethod" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="isUse">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.c_is_use" :value="scope.row.isUse" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['course:Coach:edit']">调课</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['course:Coach:remove']">注销</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

         <!-- 添加或修改教练对话框
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="125px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item v-if="tableType != '2'" label="性格特点" prop="personality">
          <el-input v-model="form.personality" placeholder="请输入性格特点" />
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="所学专业" prop="specialty">
          <el-input v-model="form.specialty" placeholder="请输入所学专业" />
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="授课方式" prop="teachMethod">
          <el-radio-group v-model="form.teachMethod">
            <el-radio v-for="dict in dict.type.c_teach_method" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="毕业院校" prop="graduate">
          <el-input v-model="form.graduate" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="岗位类型" prop="position">
          <el-radio-group v-model="form.position">
            <el-radio v-for="dict in dict.type.c_position" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="是否能试课" prop="isTestClass">
          <el-radio-group v-model="form.isTestClass">
            <el-radio v-for="dict in dict.type.course_yes_no" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="交付小组" prop="payGroupId">
          <el-select v-model="form.payGroupId" placeholder="请选择交付小组" filterable size="large" style="width: 240px">
            <el-option v-for="item in payGroups" value-key="id" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="课程分类" prop="classType">
          <el-select @change="classChange" v-model="form.classTypeName" placeholder="请选择课程分类" filterable size="large"
            style="width: 240px">
            <el-option v-for="item in classTypes" value-key="id" :key="item.id" :label="item.name" :value="item" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="所学教段" prop="teachSection">
          <el-input v-model="form.teachSection" placeholder="请输入所学教段" />
        </el-form-item>
        <el-form-item v-if="tableType == '0'" label="状态" prop="isUse">
          <el-radio-group v-model="form.isUse">
            <el-radio v-for="dict in dict.type.c_is_use" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { listCoach, listPayGroups, getCoach, delCoach, addCoach, updateCoach } from "@/api/course/Coach";
import { listType } from "@/api/business/kctype"
import { options } from "runjs";
export default {
  name: "Coach",
  dicts: ['c_is_use', 'c_position', 'sys_user_sex', 'c_teach_method'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教练表格数据
      CoachList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        phone: null,
        sex: null,
        position: null,
        payGroupName: null,
        classTypeName: null,
        teachSection: null,
        roleType: '0', // 默认查询教练列表
      },
      // 查询参数
      queryParams1: {
        pageNum: 1,
        pageSize: 9999,
        name: null,
        image: null,
        orderNum: null,
      },
      // 表单参数
      form: {},
      payGroups: [],
      classTypes: [],
      // 表单校验
      rules: {
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询教练列表 */
    getList() {
      this.loading = true;
      listCoach(this.queryParams).then(response => {
        this.CoachList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      listPayGroups().then(response => {
        console.log('[ response ] >', response)
        this.payGroups = response.data;
      });
      listType(this.queryParams1).then(response => {
        this.classTypes = response.rows;
        console.log('[ classTypes ] >', this.classTypes)
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 刷新表格
    refTable(type) {
      this.tableType = type;
      this.queryParams.roleType = type;
      this.form.roleType = type;
      console.log('[ qurey ] >', this.queryParams)
      console.log('[ roleType ] >', this.form)
      this.getList();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        roleId: null,
        roleType: this.tableType,
        name: null,
        phone: null,
        specialty: null,
        sex: null,
        personality: null,
        teachMethod: null,
        graduate: null,
        position: null,
        isTestClass: null,
        payGroupId: null,
        payGroupName: null,
        classTypeId: null,
        teachSection: null,
        isUse: null,
        createBy: null,
        createTime: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 课程分类变更时可以添加逻辑处理
    classChange(val) {
      console.log('课程分类变更:', val);
      this.form.classTypeId = val.id;
      this.form.classTypeName = val.name;
      console.log('form:', this.form);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      getCoach(id).then(response => {
        this.form = response.data;
        this.open = true;

      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认注销"' + row.name + '"教练的账号？').then(function () {
        return delCoach(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("注销成功");
      }).catch(() => { });
    },
  }
};
</script>
<style>
.example-basic .el-date-editor {
  margin: 8px;
}
</style>
